class Solution {
public:
    double myPow(double x, int n) {
        long double val=1;
        if(x==1)return 1;
        if(x==-1){
            if(abs(n)%2==1)return -1;
            if(abs(n)%2==0)return 1;
        }
        for(long int i=1;i<=abs(n);i++){
            val=val*x;
            if(abs(val)<0.00001)return 0;
            if(abs(val)>100000&&n<0)return 0;
        }
        if(n<0)return 1/val;
        if(n==0)return 1;
        if(n>0)return val;
        else return 0;
    }
};
